﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_Customer
    {
    	#region public properties
		[Required(ErrorMessage="Customer Phone Required")]
		public string CustomerPhone { get; set; }
		public string CustomerName { get; set; }
		public string Address { get; set; }
		public bool? Disabled { get; set; }
		#endregion

		#region constructor
		public pa_Customer(){ }

		public pa_Customer(IDataReader rd)
		{
			this.CustomerPhone = rd["CustomerPhone"].ToString();
			this.CustomerName = rd["CustomerName"].ToString();
			this.Address = rd["Address"].ToString();
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_Customer.Create(CustomerPhone, CustomerName, Address, Disabled);
        }

        private bool Update()
        {
            return DBpa_Customer.Update(CustomerPhone, CustomerName, Address, Disabled);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(CustomerPhone != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(string CustomerPhone)
        {
            return DBpa_Customer.Delete(CustomerPhone);
        }

        public static List<pa_Customer> GetAll()
        {
            return ObjectClass.CreateList<pa_Customer>(DBpa_Customer.GetAll());
        }

        public static pa_Customer GetByKey(string CustomerPhone)
        {
            return ObjectClass.CreateInstance<pa_Customer>(DBpa_Customer.GetByKey(CustomerPhone));
        }

        public static List<pa_Customer> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_Customer>(DBpa_Customer.GetByTop(top, where, order));
        }
		#endregion
	}
}
